//
//  PlSPathToDisplayName.m
//  PlugSuit
//
//  Created by ∞ on 16/12/07.
//  Copyright 2007 Emanuele Vulcano (infinite-labs.net). All rights reserved.
//

#import "PlSTransformers.h"
#import "PlSPlugIn.h"

@implementation PlSPathToDisplayName

+ (Class) transformedValueClass { return [NSString class]; }
+ (BOOL)allowsReverseTransformation { return NO; }

- (id) transformedValue:(id) value {
	return [[[NSFileManager defaultManager] displayNameAtPath:value] stringByDeletingPathExtension];
}

@end

@implementation PlSPathToIcon

+ (Class) transformedValueClass { return [NSImage class]; }
+ (BOOL)allowsReverseTransformation { return NO; }

- (id) transformedValue:(id) value {
	NSImage* icon = [[NSWorkspace sharedWorkspace] iconForFile:value];
	[icon setSize:NSMakeSize(32, 32)];
	return icon;
}

@end

@implementation PlSArrayToBoolIsEmpty

+ (Class) transformedValueClass { return [NSNumber class]; }
+ (BOOL)allowsReverseTransformation { return NO; }

- (id) transformedValue:(id) value {
	return [NSNumber numberWithBool:(([(NSArray*)value count] == 0)? YES : NO)];
}

@end

@implementation PlSPlugInsToBoolAnyIsManaged

+ (Class) transformedValueClass { return [NSNumber class]; }
+ (BOOL) allowsReverseTransformation { return NO; }

- (id) transformedValue:(id) value {
	for (PlSPlugIn* pin in value) {
		if (!pin.isManaged)
			return [NSNumber numberWithBool:NO];
	}
	
	return [NSNumber numberWithBool:YES];
}

@end

